function generateHtmlForService(item) {
	// alert(item['id']+'\n'+item['turn_types']+'\n'+item['worker_nos']+'\n'+item['call_turn_worker_no']+'\n'+item['billing_service_ids']);
	var html = '';
	var noWorker = item['worker_nos'] == null || item['worker_nos'] == '';
	var turnTypes = item['turn_types'] == null ? [] : item['turn_types']
			.split(',');
	var workerNos = item['worker_nos'] == null ? [] : item['worker_nos']
			.split(',');
	var callTurnWorkerNos = item['call_turn_worker_no'] == null ? []
			: item['call_turn_worker_no'].split(',');
	var billing_service_ids = item['billing_service_ids'] == null ? []
			: item['billing_service_ids'].split(',');
	for ( var j in billing_service_ids) {
		g_chose_billing_service[billing_service_ids[j]] = {
			id : billing_service_ids[j],
			worker_no : workerNos.length > j ? workerNos[j] : null,
			turn_type : turnTypes[j],
			call_turn_worker_no : callTurnWorkerNos.length > j ? callTurnWorkerNos[j]
					: null,
			billing_item_id : item['id'],// Tofixe - douhao
		};
	}
	if (noWorker) {
		for ( var j in turnTypes) {
			if (j > 0)
				html += '<br/>';
			html += '<a href="javascript: showTurnTypeChooseAction('
					+ billing_service_ids[j] + ')" id="'
					+ billing_service_ids[j] + 'ServiceTurnType">'
					+ POJO['TurnType'][turnTypes[j]] + '</a>';
			html += '|<a href="javascript: changeWorkerAction('
					+ billing_service_ids[j] + ')" id="'
					+ billing_service_ids[j] + 'WorkerNo">无技师</a>';
		}
		;
	} else {
		for ( var j in turnTypes) {
			if (j > 0)
				html += '<br/>';
			html += '<a href="javascript: showTurnTypeChooseAction('
					+ billing_service_ids[j] + ')" id="'
					+ billing_service_ids[j] + 'ServiceTurnType">'
					+ POJO['TurnType'][turnTypes[j]] + '</a>';
			html += '|<a href="javascript: changeWorkerAction('
					+ billing_service_ids[j] + ')" id="'
					+ billing_service_ids[j] + 'WorkerNo">' + workerNos[j]
					+ '</a>';
		}
		;
	}
	return html;
}

function generateHtmlForBilling(billing, number) {
	$('#tokenNoSelected').html(number == '' || number == null ? '未选中' : number);
	$('#billingDetail_billingNo').html(billing['billing_no']);
	$('#billingDetail_crtUser').html(billing['crt_user']);
	$('#billingDetail_crtDate').html(billing['crt_date']);
	var html = '';
	for ( var i in billing['billingItems']) {
		var item = billing['billingItems'][i];
		html += '<tr id="billingItemTr' + item['id'] + '">';
		if (item['status'] == 'Cancelled') {
			html += '<td class="cmm" style="color: orange"><del>';
			html += item['product_name'];
			html += '</del></td>';
			html += '<td class="cmm_n" style="color: orange"><del>'
					+ item['qty'] + '</del></td>';
			html += '<td class="cmm" style="color: orange">&nbsp;</td>';
			html += '<td class="cmm" style="color: orange">&nbsp;</td>';
		} else {
			html += '<td class="cmm">' + item['product_name'] + '</td>';
			html += '<td class="cmm_n">' + item['qty'] + '</td>';
			html += '<td class="cmm">&nbsp;';
			if (biz_billing_item_ifServeReady(item)) {
				html += '<a href="javascript: cancelItemAction(' + item['id']
						+ ')">取消</a>&nbsp;';
				html += '<a href="javascript: startServiceAction(' + item['id']
						+ ')">开始</a>&nbsp;';
				html += '</td><td class="cmm">';
				html += generateHtmlForService(item);
				html += '</td>';
			} else if (biz_billing_item_ifOngoing(item)) {
				html += '<a href="javascript: cancelItemAction(' + item['id']
						+ ')">取消</a>&nbsp;';
				html += '<a href="javascript: endServiceAction(' + item['id']
						+ ')">结束</a>(';
				html += Common.formatTime(item['plan_end_time']);
				html += ')&nbsp;';
				html += '</td><td class="cmm">';
				html += generateHtmlForService(item);
				html += '</td>';
			} else if (biz_billing_item_ifEnd(item)) {
				html += '<a href="javascript: cancelItemAction(' + item['id']
						+ ')">取消</a>&nbsp;';
				html += '<a href="javascript: antiEndAction(' + item['id']
						+ ')">反落钟</a>&nbsp;';
				html += '</td><td class="cmm">';
				html += '</td>';
			} else if (!biz_billing_item_ifTimerItem(item)) {
				html += '';
				html += '</td><td class="cmm">&nbsp;</td>';
			} else {
				html += '</td><td class="cmm">不明状态</td>';
			}
			;
		}
		html += '</tr>';

	}
	return html;
}

function generateHtmlForTokenPanel(numbers, list) {
	var html = '<tr>';
	var startIndex = numbers['firstIndexOfCurPage'];
	var endIndex = numbers['lastIndexOfCurPage'];
	if (startIndex >= numbers['totalNum']) {
		$('#tokenListTable').html('');
		return;
	}
	var ifNeedStartOfTr = true;
	var ifNeedEndOfTr = false;
	for ( var i = 0; i < g_numPerRow * g_rowPerPage; i++) {
		if (ifNeedStartOfTr) {
			html += "<tr align='center'>";
			ifNeedStartOfTr = false;
			ifNeedEndOfTr = true;
		}
		if (startIndex + i < endIndex) {
			var t = list[startIndex + i];
			if (t['status'] == 'free') {
				html += "<td class='tdList free' style='" + g_widthCell + "'>"
						+ t['tokenNo'] + "</td>";
			} else if (t['status'] == 'used') {
				html += "<td class='tdList used' style='" + g_widthCell + "'>"
						+ t['tokenNo'] + "</td>";
			} else {
				html += "<td class='tdList unknown' style='" + g_widthCell
						+ "' >" + t['tokenNo'] + "</td>";
			}
			;
		} else {
			html += "<td class='tdList free'>&nbsp;</td>";
		}
		if (ifNeedEndOfTr && (i + 1) % g_numPerRow == 0) {
			ifNeedEndOfTr = false;
			ifNeedStartOfTr = true;
			html += '</tr>';
		}
		;
	}
	return html;
}

function generateFormForStartService(itemId, serviceIds, workerNos, turnTypes, callTurnWorkerNos){
	var html = '';
	for(var i in serviceIds){
		html += '<input type="hidden" name="serviceIds" value="'+serviceIds[i]+'" />';
		html += '<input type="hidden" name="workerNos" value="'+workerNos[i]+'" />';
		html += '<input type="hidden" name="turnTypes" value="'+turnTypes[i]+'" />';
		if(callTurnWorkerNos[i]==null||callTurnWorkerNos[i]==''){
			html += '<input type="hidden" name="callTurnWorkerNos" />';
		}else{
			html += '<input type="hidden" name="callTurnWorkerNos" value="'+callTurnWorkerNos[i]+'" />';
		};
	}
	html += '<input type="hidden" name="billingId" value="'+g_context['billing']['id']+'" />';
	html += '<input type="hidden" name="billingItemId" value="'+itemId+'" />';
	html += '<input type="hidden" name="tokenNo" value="'+$('#tokenNoSelected').html()+'" />';
	return html;
}

function genereateFormForOpenToken(g_tokenNoListSelected){
	var html = '';
	for(var i in g_tokenNoListSelected){
		html += '<input type="hidden" name="tokenNos" value="'+g_tokenNoListSelected[i]+'" />';
	}
	html += '<input type="hidden" name="contactStaffNo" value="'+$('#contactStaffNo').val()+'" />';
	return html;
}